/**
 * @(#) ProfileDetailProxy.as
 *
 * @date		2009. 02. 12.
 * @version		1.0
 * @author		Shin, Yunwoo
 * @description	발령사항 - Proxy
 * 				인사기록을 조회하는 Model Logic 
 */
package com.skt.common_hr.search.model
{
	import com.skt.common_hr.common.Variables;
	import com.skt.common_hr.common.puremvc.CommonProxy;
	import com.skt.common_hr.search.SearchFacade;
	import com.skt.common_hr.search.model.vo.CareerVO;
	import com.skt.common_hr.search.model.vo.Cn01VO;
	import com.skt.common_hr.search.model.vo.EducationVO;
	import com.skt.common_hr.search.model.vo.FamilyVO;
	import com.skt.common_hr.search.model.vo.LanguageVO;
	import com.skt.common_hr.search.model.vo.LicenseVO;
	import com.skt.common_hr.search.model.vo.OfficialAnnVO;
	import com.skt.common_hr.search.model.vo.PrivateVO;
	import com.skt.common_hr.search.model.vo.ScholarshipVO;
	import com.wcl.dataloader.*;
	import com.wcl.utils.DateUtil;
	
	import mx.collections.ArrayCollection;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	
	public class ProfileDetailProxy extends CommonProxy
	{
		public static const NAME:String = "ProfileDetailProxy";
		
		public var privateDetail:PrivateVO;
		public var officalAnn:ArrayCollection;
		public var career:ArrayCollection;
		public var scholarship:ArrayCollection;
		public var family:ArrayCollection;
		public var education:ArrayCollection;
		public var language:ArrayCollection;
		public var license:ArrayCollection;
		public var cn01:ArrayCollection;

		/**
		 * 생성자
		 * 
		 * @param
		 * @return void
		 */
		public function ProfileDetailProxy(data:Object=null)
		{
			super(NAME, data);
		}
		
		
		/**
		 * data load를 수행
		 * 		- DataLoader 를 생성하고 Import Parameter 객체를 생성, RFC를 호출
		 * 
		 * @param pernr 사번
		 * @return void
		 */
		public function load(pernr:String):void
		{
			var param:Object = new Object();
			param["I_PERNR"] = pernr;
			loadData((Variables.country!="CN")?"Z_HR_0007":"Z_HR_0007_CN", param, result, fault);
		}
		
		
		
		
		
		
		///////////////////////////////////////////////////////////////////////////////////////////////////
		//
		//	Event Listeners
		//
		///////////////////////////////////////////////////////////////////////////////////////////////////
		/**
		 * 서버에서 정상적으로 리턴된 결과를 처리
		 * 
		 * @param
		 * @return void
		 */
		public function result(event:ResultEvent):void
		{
			if(event.result["RETCODE"]==0) {  
				privateDetail = parsePrivate(event.result.RESULT1[0]);
				officalAnn    = parseOfficialAnn(event.result.RESULT2);
				career        = parseCareer(event.result.RESULT3);
				scholarship   = parseScholarship(event.result.RESULT4);
				family        = parseFamily(event.result.RESULT5);
				education     = parseEducation(event.result.RESULT7);
				language      = parseLanguage(event.result.RESULT8);
				license       = parseLicense(event.result.RESULT9);
				if(Variables.country == "CN") {
					cn01		  = parseCn01(event.result.RESULT15);
				}
				 
				facade.sendNotification(SearchFacade.LOAD_PROFILE_DETAIL_COMPLETE, this);
			}
			else {
				facade.sendNotification(SearchFacade.LOAD_PROFILE_DETAIL_FAILED, this);
			}
		}
		
		/**
		 * 서버에서 오류가 발생했을 처리
		 * 
		 * @param
		 * @return void
		 */
		private function fault(event:FaultEvent):void
		{
			facade.sendNotification(SearchFacade.LOAD_PROFILE_DETAIL_FAILED, this);
		}
		
		
		
		
		
		///////////////////////////////////////////////////////////////////////////////////////////////////
		//
		//	Data Parsing functions
		//
		///////////////////////////////////////////////////////////////////////////////////////////////////
		
		/**
		 * 서버에서 전달된 result 객체를 분석하여 Value Object를 생성
		 * 
		 * @param
		 * @return 개인신상 Value Object
		 */
		private function parsePrivate(retObj:Object):PrivateVO
		{
			var vo:PrivateVO = new PrivateVO();
 			
			vo.CH_NAME		= retObj["CH_NAME"];		//성명(한자)
			vo.EN_NAME		= retObj["EN_NAME"];		//성명(영문. 이름-성 순)
			vo.GESCHT		= retObj["GESCHT"];			//성별
			if(Variables.country == "CN") {
				vo.ICNUM = retObj["ICNUM"];
				vo.RACKY = retObj["RACKY"];
				vo.RACKYT = retObj["RACKYT"];
				vo.GBDEP = retObj["GBDEP"];
				vo.GBDEPT = retObj["GBDEPT"];
				vo.PCODE = retObj["PCODE"];
				vo.PCODET = retObj["PCODET"];
			}
			else {
				vo.REGNO		= vo.getPid(retObj["REGNO"]);	//주민등록번호 (한국)
			}
			vo.FAMDT		= DateUtil.stringToDateTime(retObj["FAMDT"]);			//현재 결혼 여부의 효력 시작일
			vo.GBDAT		= DateUtil.stringToDateTime(retObj["GBDAT"]);			//생년월일
			vo.GUBUNT		= retObj["GUBUNT"];			//생일구분(음/양력)
			vo.WKADDR		= retObj["WKADDR"];			//근무지 주소
			vo.BLOODT		= retObj["BLOODT"];			//혈액형
			vo.TALL			= retObj["TALL"];			//신장
			vo.WEIGHT		= retObj["WEIGHT"];			//체중
			vo.ADDRE1		= retObj["ADDRE1"];			//본적
			vo.ADDRE2		= retObj["ADDRE2"];			//현주소
			vo.ADDRE3		= retObj["ADDRE3"];			//주민등록주소
			vo.SERTYT		= retObj["SERTYT"];			//군별
			vo.MRANKT		= retObj["MRANKT"];			//계급
			vo.EARRT		= retObj["EARRT"];			//제대구분
			vo.TEL_OFFICE	= retObj["TEL_OFFICE"];		//회사전화
			vo.TEL_HOME		= retObj["TEL_HOME"];		//집전화
			vo.TEL_MOBILE1	= retObj["TEL_MOBILE1"];	//핸드폰 1
			vo.TEL_MOBILE2	= retObj["TEL_MOBILE2"];	//핸드폰 2
			vo.FAX			= retObj["FAX"];			//FAX
			vo.EMAIL_IN		= retObj["EMAIL_IN"];		//사내메일
			vo.EMAIL_EX		= retObj["EMAIL_EX"];		//사외메일
			
			return vo;
		}
		
		/**
		 * 서버에서 전달된 result 객체를 분석하여 Value Object를 생성
		 * 
		 * @param
		 * @return 발령사항 Value Object
		 */
		private function parseOfficialAnn(src:ArrayCollection):ArrayCollection
		{
			var officialAnnColl:ArrayCollection = new ArrayCollection();
			
			for each (var item:Object in src)
			{
				var vo:OfficialAnnVO = new OfficialAnnVO;
				
				vo.BEGDA	=	DateUtil.stringToDateTime(item.BEGDA);	//BEGDA
				vo.MNTXT	=	item.MNTXT;	//발령 유형 이름
				vo.MGTXT	=	item.MGTXT;	//발령 사유 이름
				vo.ORGTX	= 	item.ORGTX;	//부서명(상위조직명 포함)
				vo.JCTXT	=	item.JCTXT;	//직책
				vo.JGTXT	=	item.JGTXT;	//직군
				vo.JMTXT	=	item.JMTXT;	//직무
				
				officialAnnColl.addItem(vo);
			}
			return officialAnnColl;
		}
		
		/**
		 * 서버에서 전달된 result 객체를 분석하여 Value Object를 생성
		 * 
		 * @param
		 * @return 경력사항 Value Object
		 */
		private function parseCareer(src:ArrayCollection):ArrayCollection
		{
			var career:ArrayCollection = new ArrayCollection;
			
			for each(var item:Object in src)
			{
				var vo:CareerVO = new CareerVO;
				
				vo.ARBGB	= item.ARBGB;		//회사이름
				vo.BEGDA	= DateUtil.stringToDateTime(item.BEGDA);		//시작일
				vo.ENDDA	= DateUtil.stringToDateTime(item.ENDDA);		//종료일
				vo.SKGYNT	= item.SKGYNT;		//회사구분
				vo.LSTJW	= item.LSTJW;		//최종직위
				vo.ORT01	= item.ORT01;		//근무지
				vo.LSTJM	= item.LSTJM;		//최종담당업무
				career.addItem(vo);
			}
			return career;
		}
		
		/**
		 * 서버에서 전달된 result 객체를 분석하여 Value Object를 생성
		 * 
		 * @param
		 * @return 학력사항 Value Object
		 */
		private function parseScholarship(src:ArrayCollection):ArrayCollection
		{
			var scholarship:ArrayCollection = new ArrayCollection;
			
			for each(var item:Object in src)
			{
				var vo:ScholarshipVO = new ScholarshipVO;
				
				vo.STEXT	= item.STEXT;	//교육 기관 텍스트
				vo.BEGDA	= DateUtil.stringToDateTime(item.BEGDA);	//시작일
				vo.ENDDA	= DateUtil.stringToDateTime(item.ENDDA);	//종료일
				vo.SCHCDT	= item.SCHCDT;	//학교
				vo.SLTPTX	= item.SLTPTX;	//전공텍스트
				vo.LOCAT	= item.LOCAT;	//소재지
				if(item.ENTCH == "X")
				{
					vo.ENTCH = "입사당시학력";
				}
				else {
					vo.ENTCH = item.ENTCH;	//입사 당시 학력
				}
				scholarship.addItem(vo);
			}
			return scholarship;
		}
		
		/**
		 * 서버에서 전달된 result 객체를 분석하여 Value Object를 생성
		 * 
		 * @param
		 * @return 가족사항 Value Object
		 */
		private function parseFamily(src:ArrayCollection):ArrayCollection
		{
			var family:ArrayCollection = new ArrayCollection;
			
			for each(var item:Object in src)
			{
				var vo:FamilyVO = new FamilyVO;
				
				vo.FNAME	= item.FNAME;	//성명
				vo.AGE		= item.AGE;		//나이
				//vo.REGNO	= item.REGNO;	//주민등록번호 (한국)
				if(Variables.country == "CN") {
					vo.FAMSAT	= item.FAMSAT;	//관계
					vo.ICNUM	= item.ICNUM;	//Identity Number(중국)
					vo.PCODE	= item.PCODE;	//정치면모
					vo.PCODET	= item.PCODET;	//
					vo.TELNR	= item.TELNR;
					vo.WTEXT	= item.WTEXT;
					vo.EGATX	= item.EGATX;
				}
				else {
					vo.KDSVHT	= item.KDSVHT;	//관계
					vo.REGNO	= vo.getPid(item.REGNO);	//주민등록번호 (한국)
					vo.LIVID	= item.LIVID;	//동거여부
					vo.HNDID	= item.HNDID;	//장애여부
					vo.DPTID	= item.DPTID;	//부양가족여부
				}
				family.addItem(vo);
			}
			return family;
		}
		
		/**
		 * 서버에서 전달된 result 객체를 분석하여 Value Object를 생성
		 * 
		 * @param
		 * @return 교육기록 Value Object
		 */
		private function parseEducation(src:ArrayCollection):ArrayCollection
		{
			var education:ArrayCollection = new ArrayCollection;
			
			for each(var item:Object in src)
			{
				var vo:EducationVO = new EducationVO;
				
				vo.BEGDA	= DateUtil.stringToDateTime(item.BEGDA);	//시작일
				vo.ENDDA	= DateUtil.stringToDateTime(item.ENDDA);	//종료일
				vo.CUTXT	= item.CUTXT;	//교육분야
				vo.STEXT	= item.STEXT;	//과정명
				vo.DEGRE	= item.DEGRE;	//차수
				vo.COMPLT	= item.COMPLT;	//이수내역
				vo.HOURS	= item.HOURS;	//교육참여시간
				education.addItem(vo);
			}
			return education;
		}
		
		/**
		 * 서버에서 전달된 result 객체를 분석하여 Value Object를 생성
		 * 
		 * @param
		 * @return 외국어심험 Value Object
		 */
		private function parseLanguage(src:ArrayCollection):ArrayCollection
		{
			var language:ArrayCollection = new ArrayCollection;
			
			for each(var item:Object in src)
			{
				var vo:LanguageVO = new LanguageVO;
				
				vo.CODE_TEXT	= item.CODE_TEXT;	//시험명
				vo.BEGDA		= DateUtil.stringToDateTime(item.BEGDA);		//시험일자
				vo.SCORE		= item.SCORE;		//교육분야
				vo.LSCOR		= item.LSCOR;		//청취점수
				vo.RSCOR		= item.RSCOR;		//독해점수
				vo.TSCOR		= item.TSCOR;		//회화점수
				vo.GSCOR		= item.GSCOR;		//어법/쓰기점수
				vo.GRADE		= item.GRADE;		//합격등급
				vo.CONST		= item.CONST;		//시행기관
				language.addItem(vo);
			}
			return language;
		}
		
		/**
		 * 서버에서 전달된 result 객체를 분석하여 Value Object를 생성
		 * 
		 * @param
		 * @return 외국어심험 Value Object
		 */
		private function parseLicense(src:ArrayCollection):ArrayCollection
		{
			var license:ArrayCollection = new ArrayCollection;
			
			for each(var item:Object in src)
			{
				var vo:LicenseVO = new LicenseVO;
				
				vo.CERNM		= item.CERNM;		//자격증 명칭
				vo.GRDNM		= item.GRDNM;		//자격증 등급
				vo.BEGDA		= DateUtil.stringToDateTime(item.BEGDA);		//시작일
				vo.LICEN		= item.LICEN;		//자격증 번호
				vo.VALID		= item.VALID;		//인증기관
				vo.REMAR		= item.REMAR;		//비고
				license.addItem(vo);
			}
			return license;
		}
		/**
		 * 서버에서 전달된 result 객체를 분석하여 Value Object를 생성
		 * 
		 * @param
		 * @return 외국어심험 Value Object
		 */
		private function parseCn01(src:ArrayCollection):ArrayCollection
		{
			var cn01List:ArrayCollection = new ArrayCollection;
			
			for each(var item:Object in src)
			{
				var vo:Cn01VO = new Cn01VO;
				
				vo.DOCNM = item.DOCNM;			//Personal file number
				vo.DOCAT = item.DOCAT;			//Personal file category
				vo.DOCTX = item.DOCTX;			//Text for Personal File Category
				vo.PLCOD = item.PLCOD;			//Personal file holding location code
				vo.PLACE = item.PLACE;			//Personal file holding location
				vo.FRMTO = item.FRMTO;			//From/To category
				vo.FTTXT = item.FTTXT;			//From/To category text
				vo.FEEID = item.FEEID;			//Pay service fee to holding location
				vo.FEAMT = item.FEAMT;			//Service fee amount to holding location
				vo.FCURR = item.FCURR;			//Currency for service fee amount
				cn01List.addItem(vo);
			}
			return cn01List;
		}
	}
}